package com.mac.intellect_flow.admin.controller.flowable;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mac.intellect_flow.reply.PageParam;
import com.mac.intellect_flow.reply.PageResult;
import com.mac.intellect_flow.reply.R;
import com.mac.intellect_flow.sys.entity.SysExpression;
import com.mac.intellect_flow.sys.service.SysExpressionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程达式管理
 *
 * @author mac
 */
@Slf4j
@Tag(name = "流程达式管理")
@RestController
@RequestMapping("/system/expression")
public class SysExpressionController{
    @Autowired
    private SysExpressionService sysExpressionService;

    /**
     * 查询流程达式列表
     */
    @Operation(summary = "流程达式列表")
    @PreAuthorize("@ps.hasPermi('system:expression:list')")
    @GetMapping("/list")
    public R<PageResult<SysExpression>> list(SysExpression sysExpression, PageParam pageParam) {
        return R.success(sysExpressionService.queryPage(sysExpression,pageParam));
    }

    /**
     * 导出流程达式列表
     */
   /* @PreAuthorize("@ps.hasPermi('system:expression:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysExpression sysExpression) {
        List<SysExpression> list = sysExpressionService.selectSysExpressionList(sysExpression);
        ExcelUtil<SysExpression> util = new ExcelUtil<SysExpression>(SysExpression.class);
        util.exportExcel(response, list, "流程达式数据");
    }*/

    /**
     * 获取流程达式详细信息
     */
    @Operation(summary = "获取流程达式详细信息")
    @PreAuthorize("@ps.hasPermi('system:expression:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@Parameter(name = "流程达式ID") @PathVariable("id") Long id) {
        return R.success(sysExpressionService.selectSysExpressionById(id));
    }

    /**
     * 新增流程达式
     */
    @Operation(summary = "新增流程达式")
    @PreAuthorize("@ps.hasPermi('system:expression:add')")
    @PostMapping
    public R add(@RequestBody SysExpression sysExpression) {
        return R.success(sysExpressionService.insertSysExpression(sysExpression));
    }

    /**
     * 修改流程达式
     */
    @Operation(summary = "修改流程达式")
    @PreAuthorize("@ps.hasPermi('system:expression:edit')")
    @PutMapping
    public R edit(@RequestBody SysExpression sysExpression) {
        return R.success(sysExpressionService.updateSysExpression(sysExpression));
    }

    /**
     * 删除流程达式
     */
    @Operation(summary = "删除流程达式")
    @PreAuthorize("@ps.hasPermi('system:expression:remove')")
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids) {
        return R.success(sysExpressionService.deleteSysExpressionByIds(ids));
    }
}
